<?php

namespace app\controller\sys;

use think\facade\View;
use app\model\GuestBook as GuestBookModel;

class GuestBook extends Base
{
    protected $modelName = "GuestBook";

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $list = GuestBookModel::order('id desc')->paginate();

        View::assign('list', $list);

        return View::fetch();
    }

    /**
     * 状态修改 1,正常; 0,非正常
     */
    public static function mark($id)
    {
        try {
            $info       = GuestBookModel::find($id);
            $info->mark = 1 - $info['mark'];
            $info->save();
            return json(['code' => 0, 'msg' => '修改成功!', 'mark'=>$info->mark]);
        } catch (\Exception $e) {
            return json(['code' => 1, 'msg' => $e->getMessage()]);
        }
    }

    /**
     * 保存备注
     * @param  int  $id
     * @param  string  $remark
     * @return \think\Response\Json 
     * 
     */
    public function remark($id = 0, $remark = '')
    {
        try {
            $info         = GuestBookModel::find($id);
            $info->remark = $remark;
            $info->save();
            return json(['code' => 0, 'msg' => '修改成功!']);
        } catch (\Exception $e) {
            return json(['code' => 1, 'msg' => $e->getMessage()]);
        }
    }
}
